package GUIs;

import Configs.Config;
import Controllers.GeneratetPDF;
import Controllers.MyTableFormat;
import Controllers.NhaTroController;
import Controllers.PhongTroController;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;

public class f_nhanvien_chunhatro_qlnhatro extends javax.swing.JFrame {

    private static f_nhanvien_chunhatro_qlnhatro _instance; //Kiểm tra sự tồn tại của 2 instance trong cùng 1 form
    private final Config conn;
    private String msnv;
    private String cmndChuNhaTro;
    private NhaTroController nhaTroControl;
    private PhongTroController phongTroControl;
    private final MyTableFormat myFormat;
    private GeneratetPDF genPDF;

    public f_nhanvien_chunhatro_qlnhatro(Config conn) {
        this.conn = conn;
        initComponents();
        this.myFormat = new MyTableFormat();        
        this.myFormat.formatTable(this.tbdsnhatro);
        this.myFormat.formatTable(this.tbdsphongtro);
    }

    public static f_nhanvien_chunhatro_qlnhatro getInstance(Config conn, String msnv, String cmnd) {
        if (_instance == null) {
            _instance = new f_nhanvien_chunhatro_qlnhatro(conn);
        }
        _instance.cmndChuNhaTro = cmnd;
        _instance.msnv = msnv;
        _instance.nhaTroControl = new NhaTroController(_instance.conn);
        _instance.phongTroControl = new PhongTroController(_instance.conn);
        return _instance;
    }

    public void createAndShowUI() {
        setVisible(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popupmenudsnhatro = new javax.swing.JPopupMenu();
        menuxemchitietnhatro = new javax.swing.JMenuItem();
        menuthemnhatro = new javax.swing.JMenuItem();
        menusuattcbnhatro = new javax.swing.JMenuItem();
        menuxoattnhatro = new javax.swing.JMenuItem();
        sepnhatro_1 = new javax.swing.JPopupMenu.Separator();
        menuthemphongtroleft = new javax.swing.JMenuItem();
        sepnhatro_2 = new javax.swing.JPopupMenu.Separator();
        menuqlgiaphong = new javax.swing.JMenuItem();
        popupmenudsphongtro = new javax.swing.JPopupMenu();
        menuxemchitietphongtro = new javax.swing.JMenuItem();
        menuthemphongtro = new javax.swing.JMenuItem();
        menusuattcbphongtro = new javax.swing.JMenuItem();
        menuxoattphongtro = new javax.swing.JMenuItem();
        pnchinh = new javax.swing.JPanel();
        btntim = new javax.swing.JButton();
        btnlammoi = new javax.swing.JButton();
        btnthemnhatro = new javax.swing.JButton();
        tftim = new javax.swing.JTextField();
        sptbdsnhatro = new javax.swing.JScrollPane();
        tbdsnhatro = new javax.swing.JTable();
        spdshoadon = new javax.swing.JScrollPane();
        tbdsphongtro = new javax.swing.JTable();
        lbtitle = new javax.swing.JLabel();

        menuxemchitietnhatro.setText("Xem chi tiết nhà trọ dưới file PDF");
        menuxemchitietnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemchitietnhatroActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menuxemchitietnhatro);

        menuthemnhatro.setText("Thêm mới nhà trọ");
        menuthemnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemnhatroActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menuthemnhatro);

        menusuattcbnhatro.setText("Sửa thông tin cơ bản nhà trọ");
        menusuattcbnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menusuattcbnhatroActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menusuattcbnhatro);

        menuxoattnhatro.setText("Xóa thông tin nhà trọ");
        menuxoattnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoattnhatroActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menuxoattnhatro);
        popupmenudsnhatro.add(sepnhatro_1);

        menuthemphongtroleft.setText("Thêm mới phòng trọ");
        menuthemphongtroleft.setToolTipText("");
        menuthemphongtroleft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemphongtroleftActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menuthemphongtroleft);
        popupmenudsnhatro.add(sepnhatro_2);

        menuqlgiaphong.setText("Quản lý giá phòng");
        menuqlgiaphong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuqlgiaphongActionPerformed(evt);
            }
        });
        popupmenudsnhatro.add(menuqlgiaphong);

        menuxemchitietphongtro.setText("Xem chi tiết phòng trọ dưới file PDF");
        menuxemchitietphongtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxemchitietphongtroActionPerformed(evt);
            }
        });
        popupmenudsphongtro.add(menuxemchitietphongtro);

        menuthemphongtro.setText("Thêm mới phòng trọ");
        menuthemphongtro.setToolTipText("");
        menuthemphongtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuthemphongtroActionPerformed(evt);
            }
        });
        popupmenudsphongtro.add(menuthemphongtro);

        menusuattcbphongtro.setText("Sửa thông tin cơ bản phòng trọ");
        menusuattcbphongtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menusuattcbphongtroActionPerformed(evt);
            }
        });
        popupmenudsphongtro.add(menusuattcbphongtro);

        menuxoattphongtro.setText("Xóa thông tin phòng trọ");
        menuxoattphongtro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuxoattphongtroActionPerformed(evt);
            }
        });
        popupmenudsphongtro.add(menuxoattphongtro);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Danh sách các nhà trọ của chủ nhà trọ");
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        btntim.setText("Tìm");
        btntim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btntimActionPerformed(evt);
            }
        });

        btnlammoi.setText("Làm mới");
        btnlammoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnlammoiActionPerformed(evt);
            }
        });

        btnthemnhatro.setText("Thêm nhà trọ");
        btnthemnhatro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthemnhatroActionPerformed(evt);
            }
        });

        tftim.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tftimKeyPressed(evt);
            }
        });

        tbdsnhatro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Số GPĐKKD", "Tên nhà trọ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbdsnhatro.setComponentPopupMenu(popupmenudsnhatro);
        tbdsnhatro.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tbdsnhatro.getTableHeader().setReorderingAllowed(false);
        sptbdsnhatro.setViewportView(tbdsnhatro);
        if (tbdsnhatro.getColumnModel().getColumnCount() > 0) {
            tbdsnhatro.getColumnModel().getColumn(0).setResizable(false);
            tbdsnhatro.getColumnModel().getColumn(1).setResizable(false);
            tbdsnhatro.getColumnModel().getColumn(2).setResizable(false);
        }

        tbdsphongtro.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Mã phòng", "Giá (VND)", "Tình trạng"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbdsphongtro.setComponentPopupMenu(popupmenudsphongtro);
        tbdsphongtro.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tbdsphongtro.getTableHeader().setReorderingAllowed(false);
        spdshoadon.setViewportView(tbdsphongtro);
        if (tbdsphongtro.getColumnModel().getColumnCount() > 0) {
            tbdsphongtro.getColumnModel().getColumn(0).setResizable(false);
            tbdsphongtro.getColumnModel().getColumn(1).setResizable(false);
            tbdsphongtro.getColumnModel().getColumn(2).setResizable(false);
            tbdsphongtro.getColumnModel().getColumn(3).setResizable(false);
        }

        javax.swing.GroupLayout pnchinhLayout = new javax.swing.GroupLayout(pnchinh);
        pnchinh.setLayout(pnchinhLayout);
        pnchinhLayout.setHorizontalGroup(
            pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnchinhLayout.createSequentialGroup()
                .addComponent(tftim, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btntim)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnlammoi)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnthemnhatro)
                .addContainerGap(452, Short.MAX_VALUE))
            .addGroup(pnchinhLayout.createSequentialGroup()
                .addComponent(sptbdsnhatro, javax.swing.GroupLayout.PREFERRED_SIZE, 424, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(spdshoadon))
        );
        pnchinhLayout.setVerticalGroup(
            pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnchinhLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btntim)
                    .addComponent(tftim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnlammoi)
                    .addComponent(btnthemnhatro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnchinhLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(spdshoadon, javax.swing.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
                    .addComponent(sptbdsnhatro, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
        );

        lbtitle.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        lbtitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbtitle.setText("QUẢN LÍ NHÀ TRỌ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnchinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(343, 343, 343)
                .addComponent(lbtitle)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbtitle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnchinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(923, 556));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btntimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntimActionPerformed
        this.searchNhaTro();
    }//GEN-LAST:event_btntimActionPerformed

    private void btnlammoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnlammoiActionPerformed
        this.refreshDsNhaTro();
    }//GEN-LAST:event_btnlammoiActionPerformed

    private void tftimKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tftimKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.searchNhaTro();
        }
    }//GEN-LAST:event_tftimKeyPressed
    public void print() {
        this.pnchinh.print(null);
    }
    private void menuxemchitietnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemchitietnhatroActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            try {
                String gpkd = this.tbdsnhatro.getValueAt(row, 1).toString();
                this.genPDF = new GeneratetPDF(this.conn);
                this.genPDF.callOpen(this.genPDF.generateChiTietNhaTro(msnv, gpkd));
            } catch (ParseException ex) {
                Logger.getLogger(f_nhanvien_chunhatro_qlnhatro.class.getName()).log(Level.SEVERE, null, ex);
            }
            this.requestFocus();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng nhà trọ để xem chi tiết!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsnhatro.requestFocus();
        }
    }//GEN-LAST:event_menuxemchitietnhatroActionPerformed

    private void menuthemnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemnhatroActionPerformed
        f_nhanvien_chunhatro_nhatro_them nhatro_them = f_nhanvien_chunhatro_nhatro_them.getInstance(this.conn, this.msnv, this.cmndChuNhaTro);
        nhatro_them.createAndShowUI();
    }//GEN-LAST:event_menuthemnhatroActionPerformed

    private void menusuattcbnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menusuattcbnhatroActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            String gpkd = this.tbdsnhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_nhatro_sua nhatro_sua = f_nhanvien_chunhatro_nhatro_sua.getInstance(this.conn, this.msnv, gpkd);
            nhatro_sua.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng nhà trọ để sửa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsnhatro.requestFocus();
        }
    }//GEN-LAST:event_menusuattcbnhatroActionPerformed

    private void menuxoattnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoattnhatroActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            if (JOptionPane.showConfirmDialog(this, "Xác nhận xóa nhà trọ này?", "Xác nhận", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                String gpkd = this.tbdsnhatro.getValueAt(row, 1).toString();
                this.nhaTroControl.Delete(gpkd);
                this.refreshDsNhaTro();
            }
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng nhà trọ để xóa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsnhatro.requestFocus();
        }
    }//GEN-LAST:event_menuxoattnhatroActionPerformed

    private void menuxemchitietphongtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxemchitietphongtroActionPerformed
        int row = this.tbdsphongtro.getSelectedRow();
        if (row != -1) {
            String maPhong = this.tbdsphongtro.getValueAt(row, 1).toString();
            this.genPDF = new GeneratetPDF(this.conn);
            this.genPDF.callOpen(this.genPDF.generateChiTietPhongTro(msnv, maPhong));
            this.requestFocus();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng phòng trọ để xem chi tiết!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsnhatro.requestFocus();
        }
    }//GEN-LAST:event_menuxemchitietphongtroActionPerformed

    private void menuthemphongtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemphongtroActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            String soGPKD = this.tbdsnhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_phongtro_them phongtro_them = f_nhanvien_chunhatro_phongtro_them.getInstance(this.conn, soGPKD, this.msnv, this.cmndChuNhaTro);
            phongtro_them.clearForm();
            phongtro_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn nhà trọ để thêm phòng trọ!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsnhatro.requestFocus();
        }
    }//GEN-LAST:event_menuthemphongtroActionPerformed

    private void menusuattcbphongtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menusuattcbphongtroActionPerformed
        int rowNhaTro = this.tbdsnhatro.getSelectedRow();
        int rowPhongTro = this.tbdsphongtro.getSelectedRow();
        if (rowNhaTro != -1 && rowPhongTro != -1) {
            String soGPKD = this.tbdsnhatro.getValueAt(rowNhaTro, 1).toString();
            String maPhong = this.tbdsphongtro.getValueAt(rowPhongTro, 1).toString();

            f_nhanvien_chunhatro_phongtro_sua phongtro_sua = f_nhanvien_chunhatro_phongtro_sua.getInstance(this.conn, this.msnv, soGPKD, maPhong);
            phongtro_sua.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn phòng trọ để sửa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsphongtro.requestFocus();
        }
    }//GEN-LAST:event_menusuattcbphongtroActionPerformed

    private void menuxoattphongtroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuxoattphongtroActionPerformed
        int row = this.tbdsphongtro.getSelectedRow();
        if (row != -1) {
            if (JOptionPane.showConfirmDialog(this, "Xác nhận xóa phòng trọ này?", "Xác nhận", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                String maphong = this.tbdsphongtro.getValueAt(row, 1).toString();
                this.phongTroControl.Delete(maphong);
                this.refreshdsPhongTro();
            }
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn đối tượng phòng trọ để xóa!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsphongtro.requestFocus();
        }
    }//GEN-LAST:event_menuxoattphongtroActionPerformed

    private void menuthemphongtroleftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuthemphongtroleftActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            String soGPKD = this.tbdsnhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_phongtro_them phongtro_them = f_nhanvien_chunhatro_phongtro_them.getInstance(this.conn, soGPKD, this.msnv, this.cmndChuNhaTro);
            phongtro_them.clearForm();
            phongtro_them.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn nhà trọ để thêm phòng trọ!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsphongtro.requestFocus();
        }
    }//GEN-LAST:event_menuthemphongtroleftActionPerformed

    private void btnthemnhatroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthemnhatroActionPerformed
        f_nhanvien_chunhatro_nhatro_them nhatro_them = f_nhanvien_chunhatro_nhatro_them.getInstance(this.conn, this.msnv, this.cmndChuNhaTro);
        nhatro_them.createAndShowUI();
    }//GEN-LAST:event_btnthemnhatroActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        this.reloadContentForm();
    }//GEN-LAST:event_formWindowOpened

    private void menuqlgiaphongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuqlgiaphongActionPerformed
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            String soGPKD = this.tbdsnhatro.getValueAt(row, 1).toString();
            f_nhanvien_chunhatro_qlgiaphong qlgiaphong = f_nhanvien_chunhatro_qlgiaphong.getInstance(this.conn, soGPKD);
            qlgiaphong.createAndShowUI();
        } else {
            JOptionPane.showMessageDialog(this, "Bạn chưa chọn nhà trọ để xem giá!", "Thông báo", JOptionPane.WARNING_MESSAGE);
            this.tbdsphongtro.requestFocus();
        }
    }//GEN-LAST:event_menuqlgiaphongActionPerformed

    public void reloadContentForm() {
        try {
            this.myFormat.clearTable(this.tbdsnhatro);
            this.tftim.setText(null);
            this.nhaTroControl.Show(this.tbdsnhatro, null, this.cmndChuNhaTro);
            this.tbdsnhatro.getSelectionModel().addListSelectionListener((ListSelectionEvent event) -> {
                try {
                    int row = f_nhanvien_chunhatro_qlnhatro.this.tbdsnhatro.getSelectedRow();
                    f_nhanvien_chunhatro_qlnhatro.this.myFormat.clearTable(this.tbdsphongtro);
                    f_nhanvien_chunhatro_qlnhatro.this.phongTroControl.Show(f_nhanvien_chunhatro_qlnhatro.this.tbdsphongtro, f_nhanvien_chunhatro_qlnhatro.this.tbdsnhatro.getValueAt(row, 1).toString());
                } catch (Exception ex) {
                    //throw exception
                }
            });
        } catch (Exception ex) {
            //throw exception
        }
    }

    public void refreshDsNhaTro() {
        this.tftim.setText(null);
        this.myFormat.clearTable(this.tbdsnhatro);
        this.myFormat.clearTable(this.tbdsphongtro);
        this.nhaTroControl.Show(this.tbdsnhatro, null, this.cmndChuNhaTro);
    }

    public void refreshdsPhongTro(){
        int row = this.tbdsnhatro.getSelectedRow();
        if (row != -1) {
            this.myFormat.clearTable(this.tbdsphongtro);
            try {
                this.phongTroControl.Show(this.tbdsphongtro, this.tbdsnhatro.getValueAt(row, 1).toString());
            } catch (ParseException ex) {
                Logger.getLogger(f_nhanvien_chunhatro_qlnhatro.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void searchNhaTro() {
        String txtsearh = this.tftim.getText().trim();
        if (!txtsearh.isEmpty()) {
            this.myFormat.clearTable(this.tbdsnhatro);
            this.myFormat.clearTable(this.tbdsphongtro);
            this.nhaTroControl.Show(this.tbdsnhatro, txtsearh, this.cmndChuNhaTro);
        } else {
            JOptionPane.showMessageDialog(this, "Vui lòng nhập thông tin nhà trọ cần tìm!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            this.tftim.requestFocus();
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnlammoi;
    private javax.swing.JButton btnthemnhatro;
    private javax.swing.JButton btntim;
    private javax.swing.JLabel lbtitle;
    private javax.swing.JMenuItem menuqlgiaphong;
    private javax.swing.JMenuItem menusuattcbnhatro;
    private javax.swing.JMenuItem menusuattcbphongtro;
    private javax.swing.JMenuItem menuthemnhatro;
    private javax.swing.JMenuItem menuthemphongtro;
    private javax.swing.JMenuItem menuthemphongtroleft;
    private javax.swing.JMenuItem menuxemchitietnhatro;
    private javax.swing.JMenuItem menuxemchitietphongtro;
    private javax.swing.JMenuItem menuxoattnhatro;
    private javax.swing.JMenuItem menuxoattphongtro;
    private javax.swing.JPanel pnchinh;
    private javax.swing.JPopupMenu popupmenudsnhatro;
    private javax.swing.JPopupMenu popupmenudsphongtro;
    private javax.swing.JPopupMenu.Separator sepnhatro_1;
    private javax.swing.JPopupMenu.Separator sepnhatro_2;
    private javax.swing.JScrollPane spdshoadon;
    private javax.swing.JScrollPane sptbdsnhatro;
    private javax.swing.JTable tbdsnhatro;
    private javax.swing.JTable tbdsphongtro;
    private javax.swing.JTextField tftim;
    // End of variables declaration//GEN-END:variables
}
